<template>
  <div class="container">

    <div class="home" v-if="testStep == 1">
      <div class="home_wrapper">
        <div class="questionnaire_desc_box">
          <div class="title">尊敬的家长朋友：</div>
          <!-- <div class="desc">{{homeDesc}}</div> -->
          <div class="desc">{{homeDesc}}</div>
        </div>

        <div class="questionnaire_info_box">
          <div class="info_box" v-if="questionnaireType == 'listenToTheClass'">
            <div class="info_item fl">
              <div class="info_bg"></div>
              <div @click="popupVisible = true">
                <!-- <span class="info_label">校区:</span> -->
                <span class="info_value">{{schoolName}}</span>
                <i></i>
              </div>
            </div>

            <!-- <div class="info_item fl">
              <mt-field label="教师" v-model="teacherId"></mt-field>
            </div> -->
            <div class="info_item fr">
              <div class="info_bg"></div>
              <div>
                <span class="info_label">教师编号:</span>
                <mt-field v-model="teacherId" @blur.native.capture="inputBlur"></mt-field>
              </div>
            </div>
            <div class="clear"></div>
            
            <mt-popup
              v-model="popupVisible"
              popup-transition="popup-fade"
              closeOnClickModal="true"
              position="bottom"
            >
              <mt-picker :slots="slots" @change="onValuesChange" style="width: 100%;" showToolbar>
                <div class="picker-toolbar-title">
                  <div class="usi-btn-cancel" @click="popupVisible = !popupVisible" style="color: #fff">取消</div>
                  <div class style="color: #fff">请选择校区</div>
                  <div class="usi-btn-sure" @click="popupVisible = !popupVisible">确定</div>
                </div>
              </mt-picker>
            </mt-popup>

            
          </div>


          <div class="info_box" v-if="questionnaireType == 'midTerm'">
            <template>
              <div class="info_item fl" style="margin: 0 auto;">
                <div class="info_bg"></div>
                <div @click="popupVisible = true">
                  <!-- <span class="info_label">校区:</span> -->
                  <span class="info_value">{{schoolName}}</span>
                  <i></i>
                </div>
              </div>
              
              <mt-popup
                v-model="popupVisible"
                popup-transition="popup-fade"
                closeOnClickModal="true"
                position="bottom"
              >
                <mt-picker :slots="slots" @change="onValuesChange" style="width: 100%;" showToolbar>
                  <div class="picker-toolbar-title">
                    <div class="usi-btn-cancel" @click="popupVisible = !popupVisible" style="color: #fff">取消</div>
                    <div class>请选择校区</div>
                    <div class="usi-btn-sure" @click="popupVisible = !popupVisible">确定</div>
                  </div>
                </mt-picker>
              </mt-popup>
            </template>


            <template>
              <div class="info_item fr" style="margin: 0 auto;">
                <div class="info_bg"></div>
                <div @click="popupVisible2 = true">
                  <span class="info_value">{{className}}</span>
                  <i></i>
                </div>
              </div>
              
              <mt-popup
                v-model="popupVisible2"
                popup-transition="popup-fade"
                closeOnClickModal="true"
                position="bottom"
              >
                <mt-picker :slots="slotsClass" @change="onValuesChangeClass" style="width: 100%;" showToolbar>
                  <div class="picker-toolbar-title">
                    <div class="usi-btn-cancel" @click="popupVisible2 = !popupVisible2" style="color: #fff">取消</div>
                    <div class>请选择班级</div>
                    <div class="usi-btn-sure" @click="popupVisible2 = !popupVisible2">确定</div>
                  </div>
                </mt-picker>
              </mt-popup>
            </template>

            <div class="clear"></div>
            

            
          </div>

          <div class="btn_box">
            <div class="btn btn_start" @click="startTest">开始点评</div>
          </div>
        </div>
      </div>
    </div>

    <div class="question_page" v-if="questionModel == 0 && testStep == 2">
      <div class="question_wrapper">
        <div class="progress_box">
          <el-progress :text-inside="true" :percentage="percentage"></el-progress>
        </div>
        <div class="question_box">
          <div class="question_order">第{{activeIndex + 1}}/{{questionList.length}}题</div>

          <div class="question_star" v-if="getActiveQuestion.questionType == 1"> 
            <div class="question_content">
              <div class="question_item">
                <p>{{activeIndex + 1}}.{{getActiveQuestion.questionContent}}</p>
                <div class="rate">
                  <el-rate v-model="questionData.score" :colors="rateColors"
                  show-text :texts="getActiveRateText" :text-color="textColor" @change="changeStar"></el-rate>
                </div>
                <div class="textarea">
                  <i></i>
                  <mt-field  placeholder="写下您更多的想法吧！" type="textarea" rows="5" v-model="questionData.suggestions"></mt-field>
                </div>
              </div>

            </div>
          </div>

          <div class="question_textarea" v-if="getActiveQuestion.questionType == 3">
            <div class="question_content">
              <div class="question_item">
                <p>{{activeIndex + 1}}.{{getActiveQuestion.questionContent}}</p>
                <div class="textarea">
                  <i></i>
                  <mt-field  placeholder="写下您更多的想法吧！" type="textarea" rows="5" v-model="questionData.suggestions"></mt-field>
                </div>
              </div>
            </div>
          </div>

          <div class="question_radio" v-if="getActiveQuestion.questionType == 4">
            <div class="question_content">
              <div class="question_item">
                <p>{{activeIndex + 1}}.{{getActiveQuestion.questionContent}}</p>
                <div class="radio">
                  <mt-radio
                    v-model="questionData.chooseId"
                    :options="getActiveRateText">
                  </mt-radio>
                </div>
              </div>
            </div>
          </div>



          <div class="btn_box">
            <div class="btn btn_prev fl" @click="prevQuestion" v-if="activeIndex !== 0">上一题</div>
            <div class="btn btn_next" style="margin-right: 0;" @click="nextQuestion" v-if="activeIndex == 0">下一题</div>
            <div class="btn btn_next fr" @click="nextQuestion" v-if="activeIndex+1 != questionList.length && activeIndex !== 0">下一题</div>
            <div class="btn btn_next fr" @click="submit" v-if="activeIndex +1 == questionList.length">提交</div>
            <div class="clear"></div>
          </div>
        </div>

        
      </div>
    </div>

    <div class="question_page_checkbox" v-if="questionModel == 1 && testStep == 2">
      <div class="checkbox_page_wrapper" >
        <div class="question_content">
          <!-- <div class="content_bar"></div> -->

          <div class="content_box">

            <div class="question_item" v-for="(item, index) in questionList" :key="index">
              <div v-if="item.questionType == 2">
                <div class="question_order">第{{index+1}}题</div>
                <div class="question">
                  <p>{{index+1}}.{{item.questionContent}}</p>
                  <div class="checkbox">
                    <!-- <mt-checklist
                      @change="changeCheckbox"
                      :max="5"
                      v-model="formData[index].chooseValue"
                      :options="checkboxOptions[index]">
                    </mt-checklist> -->

                    <el-checkbox-group 
                      v-model="formData[index].chooseValue"
                      :max="5">
                      <el-checkbox v-for="city in checkboxOptions[0]" :label="city" :key="city">{{city}}</el-checkbox>
                    </el-checkbox-group>
                  </div>
                  <div class="textarea">
                    <mt-field placeholder="其他 : " type="textarea" rows="4" v-model="formData[index].suggestions"></mt-field>
                  </div>
                </div>
              </div>

              <div v-if="item.questionType == 3">
                <div class="question_item">
                  <div class="question_order">第{{index+1}}题</div>
                  <div class="question">
                    <p>{{index+1}}.{{item.questionContent}}</p>
                    
                    <div class="textarea textarea_more">
                      <i></i>
                      <mt-field  placeholder="写下您更多的想法吧！" type="textarea" rows="5" v-model="formData[index].suggestions"></mt-field>
                    </div>
                  </div>
                </div>
              </div>
            </div>


            

            <div class="btn_box">
              <div class="btn btn_submit" @click="submitSpecial">提交</div>
            </div>
          </div>

          

          
        </div>
      </div>
    </div>

    <div class="result_page" v-if="testStep == 3">
      <div class="result_page_wrapper">
        <div class="title"></div>

        <div class="content_bg" v-if="questionnaireType == 'noRegistration'">
          <p class="result_text">感谢您的耐心点评，我们将继续努力， 为您和孩子提供家门口的高品质教育！</p>
          
          <div class="reward">
            <p class="code">{{freeClassCode}}</p>
            <i><img src="../assets/img/classCode.png" alt=""></i>
            <img src="../assets/img/reward.png" alt="">
          </div>
        </div>

        <div class="content_bg noListen" v-if="questionnaireType !== 'noRegistration'">
          <div class="result_img">
            <i></i>
            <img src="../assets/img/result_star.png" alt="">
          </div>
          <p>提交成功</p>
          <p class="result_text">感谢您的耐心点评，我们将继续努力， 为您和孩子提供家门口的高品质教育！</p>
          
          
        </div>
        
        <!-- <div class="btn_box">
          <div class="btn_share" @click="reload"></div>
        </div> -->

      </div>
    </div>

    

    
  </div>
</template>

<script>
import { location } from "../assets/js/location";
const wx = require('weixin-js-sdk');

export default {
  name: 'home',
  data() {
    return {
      questionnaireType: '',        // 问卷 类型
      isSubmit: true,
      questionModel: '',
      homeDesc: '',
      testStep: 1,
      listData: [],
      formData: [],
      freeClassCode: '',
      questionData: {},
      chooseId: '',
      wxConfig: {},
      wxCode: '',
      questionModel: 0,
      userPosition: {
        lat: '',
        lng: '',
      },
      targetPosition: {             // 校区 定位
        lat: '',
        lng: '',
      },
      distance: '',
      maxDistance: 35000,
      percentage: 0,
      questionList: [],
      activeQuestion: {},
      activeIndex: null,              // 当前 问题  索引
      rateValue2: 1,
      texts: ['极差', '失望', '一般', '满意', '惊喜'],
      rateColors: { 
        1: '#fa2020', 
        2: '#9d36fe',
        3: '#3694fe',
        4: '#a5ce35',
        5: '#fdd449' 
      },
      textColor: '#fa2020',
      introduction: '',
      value: [],
      checkboxOptions: [],
      popupVisible: false,   
      popupVisible2: false,   

      schoolList: [],
      classList: [],
      slots: [{
        values: [],
      }],
      slotsClass: [{
        values: [],
      }],
      teacherId: '',
      schoolId: '',
      classId: '',
      schoolName: '',
      className: '',
      questionnaireId: '',
      openId: '',
      chooseIdArr: [],

      urlSchoolId: '',
      urlTeacherCode: '',
      
    }
  },
  created() {
   
    this.questionnaireType = this.$route.query.type;
    this.questionModel = this.$route.query.model;
    
    this.schoolId = this.$route.query.schoolId;
    this.teacherId = this.$route.query.workNo;

    
    
    /*
    * home?type=listenToTheClass&model=1

      listenToTheClass: 试听课程  1   
      noRegistration: 不报名      2   
      signUp: 报名                3
      midTerm: 期中月             4
    */

    this.initWxOpenId();

    
   
    // 问卷相关
    this.initHomeDesc(); 
    
    this.getSchoolList();

    // 微信相关
    this.initWxConfig();

    
    // if(this.openId) {
    this.getQuestion(this.questionnaireType);
    // }




  },
  mounted() {
    // this.getDistance();
    
    if(this.teacherId && this.schoolId) {
      this.startTest();
    }
  },
  watch: {
    activeIndex(newVal, oldVal) {   // 有用
      this.activeQuestion = this.getActiveQuestion
      this.initQuestionData()
    }
  },
  methods: {
    startTest() {
      if(this.schoolName == '校区选择') {
        this.$messagebox('提示', '请选择校区');
        return false
      }
      if(this.className == '班级选择') {
        this.$messagebox('提示', '请选择班级');
        return false
      }
      if(this.questionnaireType =='listenToTheClass' && !this.teacherId) {
        this.$messagebox('提示', '请输入教师编号');
        return false
      }

      if(this.questionnaireType == 'listenToTheClass') {
         if(this.distance > this.maxDistance) {
          this.$messagebox('提示', '您距离校区过远，无法点评');
          return false
        }
      }
     

      let questionnaireType = '';
      switch (this.questionnaireType) {
        case 'listenToTheClass':
          questionnaireType = 1;
          break;
        case 'noRegistration':
          questionnaireType = 2;
          break;
        case 'signUp':
          questionnaireType = 3;
          break;
        case 'midTerm':
          questionnaireType = 4;
          break;
        default:
          break;
      }


      // 验证 月度评价是否在评价时间内
      if(this.questionnaireType == 'midTerm') {
        this.$axios.get('http://39.105.125.149:8060/banma/checkQuestionnaireTime')
        .then(res => {
          console.log(res.data.data)
          if(res.data.data) {
            this.veriEvaluation(questionnaireType);
          }else{
            this.$messagebox('提示', '尚未到本月点评时间哦！');
          }
        }).catch(err => {
          
        })
      }else{
        this.veriEvaluation(questionnaireType);
      }



      
      // this.$axios.get('http://39.105.125.149:8060/banma/checkAntiCheating', {
			// 	params: {
			// 		schoolId: this.schoolId,
			// 		classesId: this.classId,
			// 		teacherId: this.teacherId,
			// 		openId: this.openId,
			// 		questionnaireType: questionnaireType,
			// 	}
			// }).then(res => {
      //   if(res.data.data) {
      //     this.testStep = 2;
      //     this.activeIndex = 0;
      //   }else{
      //     this.$messagebox('提示', '您已经进行过本问卷的点评，感谢您的宝贵反馈哦');
      //   }
      // }).catch(err => {

      // })


      
      
    },

    // 验证是否已评价
    veriEvaluation(questionnaireType) {
      this.$axios.get('http://39.105.125.149:8060/banma/checkAntiCheating', {
				params: {
					schoolId: this.schoolId,
					classesId: this.classId,
					teacherId: this.teacherId,
					openId: this.openId,
					questionnaireType: questionnaireType,
				}
			}).then(res => {
        if(res.data.data) {
          // this.getQuestion(this.questionnaireType);
          this.testStep = 2;
          this.activeIndex = 0;
        }else{
          this.$messagebox('提示', res.data.msg);
        }
      }).catch(err => {

      })
    },

    initWxOpenId() {
      let url = window.location.href;
      url = encodeURIComponent(url)
      console.log(url)
      let code = this.getUrlParam('code')
      if(!code) {
        window.location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6461e3736f9366e9&redirect_uri=${url}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`)
      } else {
        this.wxCode = code;
        this.$axios.get(`http://39.105.125.149:8060/banma/getOpenId?code=${this.wxCode}`)
        .then(res => {
          console.log(res.data)
          this.openId = res.data.data;
        }).catch(res => {
          
        })
      }

      console.log(this.wxCode);

    },

    // 获取题目
    getQuestion(type) {
      console.log(this.openId)
      this.$axios.get(`http://39.105.125.149:8060/banma/queryQuestionByQuestionnaireType?questionnaireType=${type}`)
      .then(res => {
        this.questionList = res.data.data.list;
        this.percentage = Math.ceil((this.activeIndex + 1) / this.questionList.length * 100)
        
        let chooseContentArr = [];
        this.questionList.forEach((item, index) => {
          if(this.questionModel == 1) {
            let obj = {
              questionnaireId: item.questionnaireId,
              operationalId: item.operationalIndicators,
              // openId: this.openId,
              questionId: item.questionId,
              suggestions: '',
              chooseValue: [],
              schoolName : this.schoolName,
              questionType: item.questionType,
              isMustAnswer: item.isMustAnswer,
            }
            this.formData.push(obj)
          }
          if(item.children) {
            this.checkboxData = item.children;
            item.children.forEach((item) => {
              chooseContentArr.push(item.chooseContent);
            })
            this.checkboxOptions.push(chooseContentArr)
          }

          

          // console.log(this.checkboxOptions)
        })

      }).catch(err => {
        
      })
    },

    // 获取校区
    getSchoolList() {
      this.$axios.get(`http://39.105.125.149:8060/banma/querySchoolList?schoolId=`).then(res => {
        this.schoolList = res.data.data;
        this.schoolList.forEach(item => {
          this.slots[0].values.push(item.schoolName)
        })

        if(this.schoolId) {
          this.schoolList.forEach(item => {
            if(item.schoolId == this.schoolId) {
              this.schoolName = item.schoolName
              console.log(this.schoolName)
            }
          });
        }

        let str = '校区选择'
        this.slots[0].values.unshift(str)


      }).catch(err => {

      })
    },

    // 提交
    submit() {
      this.activeQuestion = this.getActiveQuestion
      this.initQuestionData()
      this.questionData.openId = this.openId

      if(this.formData.length != this.questionList.length) {
        this.formData.push(this.questionData);
      }

      let bmAnswerCustomList = this.formData
      // console.log(bmAnswerCustomList[9])
      if(bmAnswerCustomList[9]) {
        switch (bmAnswerCustomList[9].chooseId) {     // 对 是否愿意推荐 评分
          case '41001':
            bmAnswerCustomList[9].score = 5
            break;
          case '41002':
            bmAnswerCustomList[9].score = 3
            break;
          case '41003':
            bmAnswerCustomList[9].score = 1
            break;
          default:
            break;
        }
      }

      if(this.isSubmit) {
        this.$axios.post('http://39.105.125.149:8060/banma/insertExamples', bmAnswerCustomList).then(res => {
          this.isSubmit = false;
          if(res.data.code == 200) {
            // this.freeClassCode = res.data.data;
            this.isSubmit = true;
            this.testStep = 3;
          }else{
            this.$messagebox(res.data.msg)
          }
        }).catch(err => {
          this.isSubmit = true
        })
      }
    },
    submitSpecial() {
      let chooseId = '';
      let arr = [];
      
      var flag = false;

      this.formData.forEach(item => {
        item.chooseId = '';
        item.schoolId = this.schoolId;
        item.teacherId = this.teacherId;
        item.openId = this.openId;
        // console.log(item);     // 是否必填
        
        if(item.chooseValue.length > 0) {
          item.chooseValue.forEach(checkedItem => {
            this.checkboxData.forEach(dataItem => {
              if(checkedItem == dataItem.chooseContent) {
                arr.push(dataItem.chooseId)
              }
            })
          })
          
          chooseId = arr.join(',');
          item.chooseId = chooseId;
        }else{
          item.chooseId = '';
        }

        if(item.isMustAnswer == 1) {    // 必填
          if(item.questionType == 2 && item.chooseValue.length == 0) {
            flag = true
            this.$messagebox('提示', '您还有未完成的题目哟！');
          }else if(item.questionType == 3 && item.suggestions == ''){
            flag = true
            this.$messagebox('提示', '您还有未完成的题目哟！');
          } else{
            flag = false;
          }
          
        }
      })
      
      if(!flag) {
        let bmAnswerCustomList = this.formData;

        if(this.isSubmit) {
          this.isSubmit = false;
          this.$axios.post('http://39.105.125.149:8060/banma/insertExamples', bmAnswerCustomList).then(res => {
            if(res.data.code == 200) {
              this.isSubmit = true;
              this.freeClassCode = res.data.data;
              this.testStep = 3;
            }else{
              this.$messagebox(res.data.msg)
            }
          }).catch(err => {
            this.isSubmit = true;
          })
        }
      }
        
    },

    nextQuestion() {
      if(this.activeQuestion.questionType == 1) {
        if(!this.questionData.score) {
          this.$messagebox('提示', '评价后才可进入下一题哦');
          return false;
        }
      }

      if(this.activeQuestion.questionType == 4) {
        if(!this.questionData.chooseId) {
          this.$messagebox('提示', '评价后才可进入下一题哦');
          return false;
        }
      }

      if(this.activeIndex == this.questionList.length - 1) {
        return false;
      }

      this.activeQuestion.children.forEach((item, index) => {
        if(this.questionData.score-1 == index) {
          this.questionData.chooseId = item.chooseId
        }

        if(this.questionData.chooseId == item.chooseContent) {
          this.questionData.chooseId = item.chooseId
        }
      })


      
      this.formData.push(this.questionData);

      this.activeIndex ++;
      this.percentage = Math.ceil((this.activeIndex+1) / this.questionList.length * 100)

      // console.log(this.questionData)

      this.questionData = {};

    },
    prevQuestion() {
      if(this.activeIndex == 0) {
        return false;
      }
      this.activeIndex --;
      this.percentage = Math.ceil((this.activeIndex+1) / this.questionList.length * 100)

      // this.activeQuestion = this.getActiveQuestion
      // this.initQuestionData()

      // console.log(this.formData)
      this.questionData = this.formData[this.formData.length-1]
      this.formData.pop();
      
    },

    initHomeDesc() {
      switch (this.questionnaireType) {
        case 'listenToTheClass':
          this.homeDesc = '非常感谢您对斑马公学的关注。我们一直在努力实践，希冀向每个家庭输出最优质的社区儿童教育，帮助激活孩子受益一生的学习原动力。客观与严谨始终是斑马人走向卓越的凭借，在此诚邀您留下对本次试听课的宝贵评价。'
          break;
        case 'noRegistration':
          this.homeDesc = '非常感谢您对斑马公学的关注。斑马公学一直在努力实践，输出家门口的高品质教育，帮助激活孩子受益一生的学习原动力。同时我们也知道距离优秀还有很长的路要走，而您和孩子的心声始终是我们的第一关切，诚邀您在此进行匿名问卷，我们将无比珍视这个与孩子一起成长的机会！'
          break;
        case 'signUp':
          this.homeDesc = '非常感谢您对斑马公学的信赖与认可。家长和孩子的心声始终是我们的第一关切，为了对我们的工作进行持续优化，为每个家庭输出最优质的社区儿童教育，诚邀您完成以下问卷。'
          break;
        case 'midTerm':
          this.homeDesc = '为了对孩子的学习生活情况进行持续追踪，强化家长在宝贝成长中的参与度，不断改进我们的服务工作，诚邀您针对本月度中教学管理等方面的工作进行评价。'
          break;
      
        default:
          this.homeDesc = '非常感谢您对斑马公学的关注。我们一直在努力实践，希冀向每个家庭输出最优质的社区儿童教育，帮助激活孩子受益一生的学习原动力。'
          break;
      }
    },

    initQuestionData() {
      this.questionData.schoolId = this.schoolId;
      this.questionData.schoolName = this.schoolName;
      this.questionData.teacherId = this.teacherId;
      this.questionData.questionnaireId = this.activeQuestion.questionnaireId;  // 问卷模型ID
      this.questionData.operationalId = this.activeQuestion.operationalIndicators;  // 业务指标主键
      this.questionData.openId = this.openId; 
      this.questionData.questionId = this.activeQuestion.questionId;
      this.questionData.chooseId = this.chooseId;
      this.questionData.classId = this.classId;
      this.questionData.className = this.className;
    },

    onValuesChange(picker, values) {
      this.schoolName = values[0];
      this.schoolList.forEach(item => {
        if(item.schoolName == values[0]) {
          this.schoolId = item.schoolId
          if(item.latitude) {
            this.targetPosition = {
              lat: item.latitude,
              lng: item.longitude,
            }
          }
          
        }
      })

      this.getDistance();     // 选择校区后 计算距离
      
      console.log(this.distance + '米')
      console.log('aaaaaaaaaa')
      console.log(this.maxDistance + '米')
      // alert(this.distance + '米')

      
      if(this.questionnaireType == 'midTerm') {
        this.$axios.get('http://39.105.125.149:8060/banma/queryClassBySchoolId', {
          params: {
            schoolId: this.schoolId
          }
        }).then(res => {
          this.classList = []
          this.slotsClass[0].values = []
          this.classList = res.data.data;
          this.classList.forEach(item => {
            this.slotsClass[0].values.push(item.className)
          })

          let str = '班级选择'
          this.slotsClass[0].values.unshift(str)
        }).catch(err => {

        })
      }
    },

    onValuesChangeClass(picker, values) {
      this.className = values[0];
      this.classList.forEach(item => {
        if(item.className == values[0]) {
          this.classId = item.classId
        }
      })
    },
    

    
    // 切换星星 更改 文案颜色
    changeStar(e) {   
      this.textColor = this.rateColors[e];
      
      // console.log(this.questionData)
      // console.log(this.chooseId)
      // console.log(this.formData)
    },

    // 获取距离
    getDistance() {
      this.distance = location.initDistance(this.userPosition, this.targetPosition);
    },




    initWxConfig() {
      let _this = this;
      let url = window.location.href.split('#')[0];
      url = encodeURIComponent(url)
      console.log(url);
      this.$axios.get(`http://39.105.125.149:8060/banma/getTimestampNonceStrSignature?url=${url}`)
      .then(res => {
        res = res.data.data
        // console.log(res)
        wx.config({
          debug: false, // 开启调试模式,
          appId: 'wx6461e3736f9366e9', // 必填，企业号的唯一标识，此处填写企业号corpid
          timestamp: res.timestamp, // 必填，生成签名的时间戳
          nonceStr: res.nonceStr, // 必填，生成签名的随机串
          signature: res.signature,// 必填，签名，见附录1
          jsApiList: ['openlocation', 'getLocation',] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
        });

        wx.ready(function(){
          // console.log('aaaaa')
          wx.getLocation({
            type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
            success: function (res) {
              // alert(res.latitude)
              // console.log(res)
              _this.userPosition = {
                lat: res.latitude,
                lng: res.longitude,
              }
              _this.getDistance();

            // var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
            // var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
            // var speed = res.speed; // 速度，以米/每秒计
            var accuracy = res.accuracy; // 位置精度

            },
            error(err) {
              // console.log(err);
            }
          });
        })

        wx.error(function(err){
          console.log(err)
        })


      }).catch(err => {
        
      })
    },

    is_weixin(){
      var ua = navigator.userAgent.toLowerCase(); //判断浏览器的类型
      if(ua.match(/MicroMessenger/i)=="micromessenger") {
          return true;
      } else {
          return false;
      }
    },

    getUrlParam(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    reload() {
      window.location.href = `http://www.mingxiaoclub.cn/h5evaluate/#/home?model=${this.questionModel}&type=${this.questionnaireType}`
    },

    inputBlur() {
      window.scrollTo(0, document.documentElement.clientHeight); 
    }
  },
  computed: {
    getActiveQuestion() {
      return this.questionList[this.activeIndex];
    },
    getActiveRateText() {
      let arr = [];
      this.questionList[this.activeIndex].children.forEach((item, index) => {
        arr.push(item.chooseContent)
      })
      return arr;
    },

  },
}
</script>


<style scoped>
.container {
  height: 100%;
  max-width: 750px;
  margin: 0 auto;
  overflow: auto;
}
.question_page {
  
    background: #ffa304;
}

.stepWrapper {
  width: 100%;
  height: 100%;
}

/* 问卷 结果页 */

  .result_page {
    background: #fea405;
    width: 100%;
    height: 100%;
  }
  .result_page_wrapper {
    background: url('../assets/img/result_page_bg.jpg') 0 0 no-repeat;
    background-size: 100%;
    width: 100%;
    /* height: 100%;; */
    padding: 0 60px;
    padding-top: 155px;
    box-sizing: border-box;
  }

  .result_page_wrapper .title {
    width: 372px;
    height: 84px;
    background: url('../assets/img/result_title_bg.png') 0 0 no-repeat;
    background-size: 100%;
    margin:  0 auto;
    position: relative;
  }

  .result_page_wrapper .content_bg {
    width: 100%;
    box-sizing: border-box;
    min-height: 838px;
    border-radius:20px;
    margin-top: -40px;
    background: -webkit-linear-gradient(top, #CEF273,#9CC13F); /* Safari 5.1-6.0 */
    background: -o-linear-gradient(top,#CEF273,#9CC13F); /* Opera 11.1-12.0 */ 
    background: -moz-linear-gradient(top,#CEF273,#9CC13F); /* Firefox 3.6-15 */
    background: linear-gradient(top, #CEF273,#9CC13F); /* 标准语法 */
  }

  .content_bg .result_img{
    text-align: center;
    padding-top: 120px;;
  }
  .content_bg .result_img img {
    width: 173px;
    height: 174px;
  }

  .noListen p {
    color: #fff !important;
    text-align: center;
    font-size: 40px;
  }
  .noListen p:first-child {
    font-size: 39px;
  }

  .result_page_wrapper .content_bg .result_text {
    padding: 91px;
    box-sizing: border-box;
    font-size: 28px;
    color: #ED7867;
    line-height:55px;
    text-align: justify;
  }

  .result_page_wrapper .btn_box {
    margin-top: 50px;
  }
  .result_page_wrapper .btn_share {
    width: 291px;
    height: 101px;
    background: url('../assets/img/share.png') 0 0 no-repeat;
    background-size: 100%;
    margin: 0 auto;
  }

  .result_page_wrapper .reward {
    width: 497px;
    /* height: 88px; */
    margin: 0 auto;
    text-align: center;
  }
  .result_page_wrapper .reward .code {
    color: #fff;
    font-size: 30px;
    word-wrap: break-word;
  }
  .result_page_wrapper .reward i {
    display: inline-block;
    width: 90px;
    position: relative;
    padding: 20px 70px;
    /* box-sizing: border-box; */
  }
  .result_page_wrapper .reward i:before {
    content: '';
    display: inline-block;
    width: 56px;
    height: 2px;
    background: #F9C46B;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
  }
  .result_page_wrapper .reward i:after {
    content: '';
    display: inline-block;
    width: 56px;
    height: 2px;
    background: #F9C46B;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
  }
  .result_page_wrapper .reward img {
    width: 100%;
  }
/* 问卷 结果页 */


/* 问卷 多选页 */
  .question_page_checkbox {
    background: #acd64c;
    width: 100%;
    min-height: 100%;
  }
  .checkbox_page_wrapper {
    background: url('../assets/img/question_page_checkbox_bg.jpg') 0 0 no-repeat;
    background-size: 100%;
    width: 100%;
    min-height: 1280px;
  }

  .checkbox_page_wrapper .question_content {
    padding: 0 30px;
    padding-top: 230px;
    padding-bottom: 75px;
    box-sizing: border-box;
  }
  .checkbox_page_wrapper .content_bar{
    position: relative;
    width: 100%;
    height: 34px;
    background: -webkit-linear-gradient(top, #67AC39,#B4F489); /* Safari 5.1-6.0 */
    background: -o-linear-gradient(top,#67AC39,#B4F489); /* Opera 11.1-12.0 */ 
    background: -moz-linear-gradient(top,#67AC39,#B4F489); /* Firefox 3.6-15 */
    background: linear-gradient(top, #67AC39,#B4F489); /* 标准语法 */
    border-radius: 50px;
  }
  .checkbox_page_wrapper .content_box {
    /* background: #fff; */
    border-radius: 0 0 15px 15px;
    margin: 0 6px;
    min-height: 700px;
    margin-top: -5px;
    padding-bottom: 56px;
  }
  .checkbox_page_wrapper .content_box .question_order {
    width: 310px;
    height: 69px;
    line-height: 69px;
    margin:  0 auto;
    background: #FBAB23;
    border-radius: 40px;
    font-size:38px;
    color: #fff;
    text-align: center;
    box-sizing: border-box;
  }
  .checkbox_page_wrapper .question_item .question {
    font-size: 30px;
    color: #666664;
  }
  .checkbox_page_wrapper .question_item .question p {
    padding: 24px;
    box-sizing: border-box;
    margin-bottom: 0;
    color: #fff;
    font-size:34px;
  }

  .checkbox_page_wrapper .question_item .textarea {
    margin: 30px 20px;
  }

  .checkbox_page_wrapper .textarea_more i {
    left: 29px;
    /* top: 19px; */
  }
  
  .btn_submit {
    width:310px;
    height:73px;
    line-height:73px;
    /* background:linear-gradient(139deg,rgba(171,221,36,1) 0%,rgba(141,187,15,1) 100%); */
    background: #fff;
    box-shadow:0px 6px 14px 0px rgba(66,114,34,0.2);
    border-radius:37px;
    font-size: 32px;
    color: #FFAC35 !important;
  }
  
/* 问卷 多选页 */

/*============== 问卷 星星页 ==============  */
/*============== 问卷 星星页 ==============  */


/*============== 问卷 星星页 ==============  */
  .question_page {
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
  }

  .question_wrapper {
    background: url('../assets/img/quesiton_bg.jpg') 0 0 no-repeat;
    background-size: cover;
    width: 100%;
    height: 100%;
    padding: 88px 36px;
    box-sizing: border-box;
  }

  .question_page .progress_box {
    width: 500px;
    height: 40px;
    margin: 0 auto;
  }

  .question_box{
    margin-top: 90px;
    background: #fff;
    min-height: 700px;
    border-radius: 15px;
    position: relative;
    padding: 0 50px;
    box-sizing: border-box;
  }

  .question_box .question_order {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    width: 266px;
    height: 75px;
    background: url('../assets/img/question_order_bg.png') 0 0 no-repeat;
    background-size: 100%;
    margin: 0 auto;
    font-size:32px;
    line-height: 70px;
    text-align: center;
    color: #fff;
  }
  .question_box .question_content{
    padding-top: 120px;
    font-size: 28px;
    color: #666664;
  }

  .question_item p {
    margin-bottom: 50px;
  }

  .question_star .textarea {
    position: relative;
    margin-top: 60px;
  }
  .textarea {
    position: relative;
  }
  .textarea i{
    display: inline-block;
    position: absolute;
    width: 40px;
    height: 37px;
    background: url('../assets/img/textarea_icon.png') 0 0 no-repeat;
    background-size: 100%;
    left: 50px;
    top: 50px;
    z-index: 99;
  }

  .question_page .btn_box{
    margin-top: 50px;
    padding-bottom: 40px;
  }


/*============== 问卷 星星页 ==============  */

/* ============== home page ============================ */
  .home {
    background: #8fc320;
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
  }
  .home_wrapper {
    background: url('../assets/img/home_bg.jpg') 0 0 no-repeat;
    background-size: 100%;
    width: 100%;
    /* height: 100%; */
    /* overflow: auto; */
  }

  .home .info_box{
    margin-top: 20px;
  }
  .home .info_box > .info_item {
    width: 305px;
    /* margin-right: 30px; */
    position: relative;
    height: 60px;
  }


  .home .info_box > .info_item:first-child{
    display: flex;
    font-size: 16px;
    line-height: 1;
    min-height: inherit;
    /* overflow: hidden; */
    /* padding: 10px 0; */
    align-items: center;
  }
  .home .info_box > .info_item .info_label{
    display: inline-block;
    line-height: 53px;
    padding-left: 10px;
    font-size:27px;
    width: 130px;
    position: absolute;
    z-index: 99;

  }
  
  .home .info_box > .info_item .info_value {
    display: inline-block;
    position: absolute;
    line-height: 53px;
    margin-left: 20px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 215px;
    font-size: .36rem;
  }
  /* .home .info_box > .info_item:first-child .info_value{
    font-size: 16px;
    width: 100%;
    height: 40px;
    line-height: 40px;
    display: inline-block;
    border: 1px solid #000;
  } */

  .home .info_box > .info_item > div:first-child {
    position: absolute;
    left: 0;
    top: 0;
    background: #FAB134;
    width: 285px;
    height: 53px;
  }
  .home .info_box > .info_item > div:last-child {
    position: absolute;
    left: 7px;
    top: 6px;
    background: #fff;
    width: 285px;
    height: 53px;
    z-index: 99;
  }

  .home .info_box > .info_item > div:last-child i {
    width: 18px;
    height: 16px;
    display: inline-block;
    background: url('../assets/img/icon1.png') 0 0 no-repeat;
    background-size: 100%;
    position: absolute;
    transform: translateY(-50%);
    top: 50%;
    right: 10px;
  }
  


  

  .home .questionnaire_desc_box {
    /* position: absolute; */
    padding: 0 95px;
    padding-top: 350px;
    box-sizing: border-box;
    z-index: 2;
  }
  .home .questionnaire_info_box {
    padding: 0 60px;
  }
  .home .questionnaire_desc_box .title {
    color: #FAB53F;
    font-size: 32px;
    font-weight:600;
    line-height:75px;
    font-family:MF JianHei (Noncommercial);
  }
  .home .questionnaire_desc_box .desc {
    font-size:28px;
    font-family:Source Han Sans SC;
    font-weight:500;
    color:rgba(250,181,63,1);
    text-align: justify;
    text-indent: 2em;
    line-height:52px;
    max-height: 500px;
    min-height: 500px;
  }
  .home .btn_box {
    /* position: absolute; */
    z-index: 333;
    margin-top: 30px;
    margin-bottom: 30px;
    /* bottom: 170px; */
    /* transform: translateX(-50%); */
    left: 50%;
  }
  .home .btn_start {
    width:353px;
    height:78px;
    line-height: 78px;
    background:rgba(251,171,35,1);
    box-shadow:0px 3px 25px 0px rgba(0, 0, 0, 0.21);
    border-radius:44px;
    font-size: 34px;
  }
/* ============== home page ============================ */
</style>
